﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoPoco.Engine;

namespace AutoPoco.DataSources
{
    public class DefaultIntegerSource : DatasourceBase<int>
    {
        private int? _min = null;
        private int? _max = null;
        private Random _rnd = new Random();

        public DefaultIntegerSource()
        {
        }

        public DefaultIntegerSource( int max)
        {
            _max = max;
        }

        public DefaultIntegerSource(int min, int max) : this(max)
        {
            _min = min;
        }

        public override int Next(IGenerationContext context)
        {
            if(_max.HasValue)
            {
                if (_min.HasValue)
                    return _rnd.Next(_min.Value, _max.Value);
                return _rnd.Next(_max.Value);
            }

            return 0;
        }
    }
}
